home *** CD-ROM | disk | FTP | other *** search
- Path: locutus.rchland.ibm.com!usenet
- From: pstaite@vnet.ibm.com
- Newsgroups: comp.lang.c++
- Subject: Re: Finding Permutations....????
- Date: 17 Jan 1996 22:04:14 GMT
- Organization: IBM OS/2 Device Driver Development Rochester, MN
- Message-ID: <4djrou$1at3@locutus.rchland.ibm.com>
- References: <1996Jan16.160018.24583@oasis.enmu.edu>
- Reply-To: pstaite@vnet.ibm.com
- NNTP-Posting-Host: warpone.rchland.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <1996Jan16.160018.24583@oasis.enmu.edu>, reinholj@math.enmu.edu (John Reinhold) writes:
- >I am trying to find a good way to find permutations.
- >
- >I am looking for an algorythm that would help me
- >get started, or lead me in the right direction.
-
- ..
-
- >I would not like a solution, just a lead in the right direction)
-
- OK, read the number/symbol objects into some container.
-
- Create a container of "position" objects, same length as other
- container.
-
- Recursively iterate through the position objects.
-
- At each position, iterate through all unused number/symbol objects in
- the other container. That is, mark one unused one as used, then
- recursively call the next position. After recursive call, unmark
- current number/symbol, mark next...
-
- When at the last position "boink" each position to output the
- number/symbol it has marked as used.
-
- Thus, the last position always sees a choice of only one number/symbol.
- The next to last always sees a choice of two, etc.
-
- This algorithm works (I coded a simple linked-list implementation to
- test it). Note the recursion is only as deep as the number of symbols
- so it isn't too bad. Number of permutations output grows pretty quick
- :-) though...
-
-
- Phil Staite, team OS/2
- internet: pstaite@vnet.ibm.com internal: pstaite@rchland
-
-